//
//  ZWHomeTableViewCell.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/20.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit
import SnapKit
    //昵称文字大小
let ZWStatusCellNameFontSize: CGFloat = 14
let ZWStatusCellTimeFontSize: CGFloat = 10
let ZWStatusCellContentFontSize: CGFloat = 14
let ZWStatusCellMargin: CGFloat = 10
let ZWStatusCellHeadImageW: CGFloat = 35


class ZWHomeTableViewCell: UITableViewCell {

    //toolBar顶部约束
    var toolBarTopCons:Constraint?
    var statusViewModel: ZWStatusesViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            retweetStatusView.statusViewModel = statusViewModel
            toolBarTopCons?.uninstall()
            if statusViewModel?.retweetText == nil{
                retweetStatusView.hidden = true
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                 toolBarTopCons = make.top.equalTo(originalView.snp_bottom).constraint
                })
            }else{
                retweetStatusView.hidden = false
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                   toolBarTopCons = make.top.equalTo(retweetStatusView.snp_bottom).constraint
                })
            }
        }
    }
    
//    var statusModel: ZWStatuses? {
//        didSet{
//            originalView.statusModel = statusModel
//        }
//    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        selectionStyle = .None
//        backgroundColor = UIColor.redColor()
        backgroundColor = UIColor(white: 245/255, alpha: 1)
        contentView.addSubview(originalView)
        contentView.addSubview(retweetStatusView)
        contentView.addSubview(statusToolBar)
        //约束
        originalView.snp_makeConstraints { (make) -> Void in
            make.trailing.leading.equalTo(contentView)
            make.top.equalTo(ZWStatusCellMargin)
//            make.height.equalTo(100)
        }
        
        
        retweetStatusView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
//            make.bottom.equalTo(statusToolBar.snp_top)
        }
        statusToolBar.snp_makeConstraints { (make) -> Void in
          toolBarTopCons = make.top.equalTo(retweetStatusView.snp_bottom).constraint
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(35)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(statusToolBar)
            make.leading.top.trailing.equalTo(self)
        }
    }
    
    
    private lazy var originalView:ZWOriginalView = ZWOriginalView()
    private lazy var statusToolBar:ZWStatusToolBar = ZWStatusToolBar()
    private lazy var retweetStatusView:ZWRetweetStatusView = ZWRetweetStatusView()
}
